package com.juc.blockingQueue.LinkedTransferQueue.tryTransfer1;

import java.util.concurrent.TimeUnit;

public class ThreadB1 extends Thread{

	/**
	 * tryTransfer(E e, long timeout, TimeUnit unit)
	 * 1.如果当前存在一个正在等待获取的消费者线程，则立即将数据传输给它
	 * 2.否则将把元素插入到队列尾部，等待被消费者线程获取消费掉
	 * 3.如果在指定时间内元素没有被消费者线程获取，则返回false，并且
	 * 将元素从队列中移除
	 * 
	 */
	private MyServiceB service;
	
	public ThreadB1 (MyServiceB service) {
		super();
		this.service =service;
	}
	
	@Override
	public void run() {
		
	    try {
	    	System.out.println(Thread.currentThread().getName() + "  beginA  " + System.currentTimeMillis());
			System.out.println("tryTransfer(e) 返回值为 ： " + service.queue.tryTransfer("我是元素",5,TimeUnit.SECONDS) );
			System.out.println(Thread.currentThread().getName() + "  endA  " + System.currentTimeMillis());
	    } catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		

	}
}
